// pages/dingdan/dingdan.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    teach:[],
    xiangmu:[],
    time:'',
    id:'',
    data:''
  },
  formSubmit:function(e){
    console.log(e)
    if(e.detail.value.sex == ""){
      wx.showModal({
        title: '提示',
        content: "请选择您的资料,可到个人中心填写"
      })
    }else{
    wx.request({
      url: 'https://wx.gjzy.com/weixin/Admin/Index/zhifu',
      method:"POST",
      header:{
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data:{
        id:wx.getStorageSync('id'),
        name:e.detail.value.xiangmu,
        money:e.detail.value.money,
        sex:e.detail.value.sex,
        teach:e.detail.value.teach,
        time:e.detail.value.time,
        num:e.detail.value.num
      },
      success:function(res){
        console.log(res)
        if(res.data.state == 1){
          wx.requestPayment({
            timeStamp: res.data.timeStamp,
            nonceStr: res.data.nonceStr,
            package: res.data.package,
            signType: res.data.signType,
            paySign: res.data.paySign,
            success:function(re){
              wx.showToast({
                title: '支付成功',
                success:function(){
                  wx.redirectTo({
                    url: '../yuyue/yuyue',
                  })
                }
              })
            }
          })
        } else if (res.data.state == 0) {
          wx.showToast({
            title: res.data.Msg,
            icon: 'fail',
            duration: 1000
          })
        } else if (res.data.state == 3) {
          wx.showToast({
            title: res.data.Msg,
            icon: 'fail',
            duration: 1000
          })
        } else {
          wx.showToast({
            title: '系统繁忙，请稍后重试~',
            icon: 'fail',
            duration: 1000
          })
        }
      }
    })
  }
  },
  clear:function(){
    wx.redirectTo({
      url: '../home/home',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    wx.checkSession({
      success: function () {
        wx.request({
          url: 'https://wx.gjzy.com/weixin/Admin/Index/dingdan',
          data: {
            id: wx.getStorageSync('id'),
            fid: that.options.fid,
            tid: that.options.tid,
            xid: that.options.xid,
            time: that.options.time
          },
          success: function (res) {
            that.setData({
              data: res.data.data,
              teach: res.data.teach,
              xiangmu: res.data.xiangmu
            })
          }
        })
      },
      fail: function () {
        wx.showToast({
          title:'登陆超时,请先登陆',
          icon:'loading',
          duration:3000,
          success:function(){
            wx.redirectTo({
              url: "/pages/user/user"
            })
          }
        })
      }
    })
    var that = this
    this.setData({
      num :this.options.num,
      time:this.options.time
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})